package com.fm.demo.utils

import android.graphics.drawable.Drawable
import android.view.View
import android.widget.TextView
import com.fm.common.base.Constants

/**
 * @CreateData:     2019/11/1 9:33
 * @E-Mail:         709674174@qq.com
 * @Author:         lyy
 * @Description:    扩展方法
 */
fun TextView.safeSetText(text: String? = "") {
    if (!text.isNullOrEmpty()) {
        setText(text)
        visibility = View.VISIBLE
    }
}

fun TextView.setDrawable(drawable: Drawable?, @Constants.LocationTagType location: String = Constants.TAG_LEFT) {
    if (null == drawable) {
        return
    }
    var leftDrawable: Drawable? = null
    var topDrawable: Drawable? = null
    var rightDrawable: Drawable? = null
    var bottomDrawable: Drawable? = null
    when (location) {
        Constants.TAG_LEFT -> {
            leftDrawable = drawable
        }
        Constants.TAG_TOP -> {
            topDrawable = drawable
        }
        Constants.TAG_RIGHT -> {
            rightDrawable = drawable
        }
        Constants.TAG_BOTTOM -> {
            bottomDrawable = drawable
        }
        else -> {
            return
        }
    }
    setCompoundDrawablesWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable)
    visibility = View.VISIBLE
}
